package com.atguigui.leetcode;

/**
 * 801.使序列递增的最小交换次数
 * Project: leetcode
 * Package: com.atguigui.leetcode
 * Version: 1.0
 * <p>
 * Created by WJX on 2022/10/10 9:22
 */
public class P801MinimumSwapsToMakeSequencesIncreasing {
    public static void main(String[] args) {
        Solution solution = new P801MinimumSwapsToMakeSequencesIncreasing().new Solution();
        // TO TEST
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public int minSwap(int[] nums1, int[] nums2) {
            int n = nums1.length;
            int a = 0, b = 1;
            for (int i = 1; i < n; i++) {
                int at = a, bt = b;
                a = b = n;
                if (nums1[i] > nums1[i - 1] && nums2[i] > nums2[i - 1]) {
                    a = Math.min(a, at);
                    b = Math.min(b, bt + 1);
                }
                if (nums1[i] > nums2[i - 1] && nums2[i] > nums1[i - 1]) {
                    a = Math.min(a, bt);
                    b = Math.min(b, at + 1);
                }
            }
            return Math.min(a, b);
        }
    }
}
